<?php
/** 
 * $Source: /cvsroot/pn-commerce/pn-commerce/pntemplates/plugins/function.pncCityStateZipEntryfields.php,v $
 * $Author: pcornelissen $
 * $Revision: 1.4 $
 * $Date: 2003/12/08 12:09:47 $
 *
 * Type: Function
 *
 * creates a path string to the recet category, e.g. bigthings -> smaller things -> really small things
 *@param params['CityVar']  string (mandatory) name of the datafield
 *@param params['City']     string (optional) default value
 *@param params['StateVar'] string (mandatory) name of the datafield
 *@param params['State']    string (optional) default value
 *@param params['ZipVar']   string (mandatory) name of the datafield
 *@param params['Zip']      string (optional) default value
 *@param params['Country']  string usa or canada for the state dropdown
 *@param params['Format']   string 'long' or 'short' for the ste dropdown
 *@return string path as seen in the example
 */
function smarty_function_pncCityStateZipEntryfields($params, &$smarty)
{
    extract( $params );
    if( !$CityVar )
    {  
        $smarty->trigger_error( "pncCityStateZipEntryfields: missing parameter CityVar" );
        return false;
    }
    if( !$StateVar )
    {  
        $smarty->trigger_error( "pncCityStateZipEntryfields: missing parameter StateVar" );
        return false;
    }
    if( !$ZipVar )
    {  
        $smarty->trigger_error( "pncCityStateZipEntryfields: missing parameter ZipVar" );
        return false;
    }
    if( !$Country )
    {  
        $smarty->trigger_error( "pncCityStateZipEntryfields: missing parameter Country" );
        return false;
    }
    if( ($Format) AND ( ( $Format <> 'long' ) AND ( $Format <> 'short' ) ) )
    {
        $smarty->trigger_error( "pncCityStateZipEntryfields: wrong parameter $Format in Format" );
        return false;
    }

    $adr = pnModGetVar( 'pncommerce', 'AddressFormat' );
    if( !$adr )
    {
        $smarty->trigger_error( "pncCityStateZipEntryfields: error in shopconfiguration, address format not set" );
        return false;
    }
    
    if( pnModAPILoad( 'pncommerce', 'user' ) )
    {
        $adr = ereg_replace( "%c", "<input type='text' name='$CityVar' value='$City' size=25>", $adr );
        $adr = ereg_replace( "%z", "<input type='text' name='$ZipVar' value='$Zip' size=7 maxlength=12>", $adr );
        $adr = ereg_replace( "%s", pnModAPIFunc( 'pncommerce', 'user', 'getFederalStateListForSelect',
                                                 array( 'VariableName'  => $StateVar,
                                                        'SelectedState' => $State,
                                                        'Format'        => $Format,
                                                        'Country'       => $Country ) ), $adr );
        return $adr;
    }
    else
    {
        $smarty->trigger_error( "pncCityStateZipEntryfields: cannot load pnuserapi", E_USER_ERROR );
        return false;
    }
}
?>
